openerp.pm = function(instance)  {
    
    var _t = instance.web._t,
		_lt = instance.web._lt;
    var QWeb = instance.web.qweb;
    
    instance.pm={};
    
    aa = new instance.web.CompoundContext();
 
 		instance.pm.view = instance.web.Widget.extend({
 			template:"demo",
    	start:function(){
    		$(".demo1_div").append("<div class='demo1_div_title'>\
    					<span id='demo1_div_title'>开始视图</span>\
    					<span id='demo1_div_sub_title'>(选择项目)</span>\
    				</div>");

				$("#demo_right_bar_start_control_show").html("开始");
				$("#demo_right_bar_project_control_show").html("项目");
				$("#demo_right_bar_area_control_show").html("分区");
				$("#demo_right_bar_building_control_show").html("楼栋");
/*				
				$("#demo_right_bar_start_control_show").click(function(){
					$(".demo_right_bar_control_show").hide();
					$(".demo_right_bar_control_show:eq(0)").show();
					$(".demo_right_bar_control_show:eq(1)").show();
					project();
																
				});
*/				
			function view_start(){
				project();				
				
			}

			view_start();

			function project(){

					$("#demo_right_bar_project div").empty();
					$("#demo_right_bar_project_title").append("<h2>项目选择:</h2>");
					$("#demo_right_bar_project_control_full").html("<img src='pm/static/src/img/full.png' width=15px height=15px></img>");					  
					$("#demo_right_bar_project_control_hide").html("<img src='pm/static/src/img/close.png' width=15px height=15px></img>");

					$("#demo_right_bar_project_control_full").click(function(){
						$(".demo_right_bar_body_project").hide("drop",{direction:"right"},400);
						$("#demo_right_bar_project").hide("drop",{direction:"right"},500);
						for (i=0;i<5;i++)
						{
							if ($(".demo_right_bar:eq("+i+")").length && $(".demo_right_bar_title:eq("+i+")").html())
							{
								$(".demo_right_bar_control_show:eq("+i+")").show();
							}
						}
						$(".demo2_div_body").hide();
						$(".demo3_div").hide();
						$("#demo2_div_project").show();						
						$("#demo1_div_title").html("开始视图");
  					$("#demo1_div_sub_title").html("(项目分布)");						
					});
					
					$("#demo_right_bar_project_control_hide").click(function(){
						$(".demo_right_bar_body_project").hide("drop",{direction:"right"},400);
						$("#demo_right_bar_project").hide("drop",{direction:"right"},500);
						for (i=0;i<5;i++)
						{
							if ($(".demo_right_bar:eq("+i+")").length && $(".demo_right_bar_title:eq("+i+")").html())
							{
								$(".demo_right_bar_control_show:eq("+i+")").show();
//								$(".demo_right_bar_control_show:eq("+(i+1)+")").show();	
							}
						}											
					});
					$("#demo_right_bar_project_control_show").click(function(){
						$("#demo_right_bar_project").show("drop",{direction:"right"},500);
						$(".demo_right_bar_body_project").show("drop",{direction:"right"},500);
						$(".demo_right_bar_control_show").hide();
					});
  				new instance.web.Model("pm.project").query(["name","code","plot_address_map"]).all().then(function(result){
  					for (i=0;i<result.length;i++)
  					{
  						$("#demo_right_bar_project_body").append("<div id='demo_right_bar_project_"+result[i].id+"' \
  									class='demo_right_bar_body_project'>"+result[i].name+"</div>");
  									
  						$("#demo_right_bar_project_"+result[i].id).click(function(){
  							project_id = parseInt($(this).attr('id').split('demo_right_bar_project_')[1]);
  							
 								new instance.web.Model("pm.project").query(["name","code","plot_address_map"]).filter([['id','=',project_id],]).all().then(function(result2){  							
  								
  								area(project_id,result2[0].name,result2[0].plot_address_map);
  							});						  							
  						});
  					}
//  					$("#demo_right_bar_start_control_show").show();	  					
  					$("#demo_right_bar_project_control_show").show();					
  
  				});

					$("#demo1_div_title").html("开始视图");
  				$("#demo1_div_sub_title").html("(项目分布)");


					$(".demo2_div_body").hide();
					$(".demo3_div").hide();
  				$("#demo2_div_project").remove();
  				$(".demo2_div").append("<div id='demo2_div_project' class='demo2_div_body'></div>");
  				$("#demo2_div_project").append("<div id='demo2_div_project_left'>项目分布:</div>");
  				$("#demo2_div_project_left").append("<div style='float:right;'>快速定位：\
  							<select id='demo2_div_project_left_map_select'style='margin-right:2px;'><option val='none'>未选择</option></select>\
  							</div>");
 				
  				$("#demo2_div_project").append("<div id='demo2_div_project_body'></div>");
  				
//					$("#demo2_div_project_body").css({'height':$(".demo2_div").height()-50+'px','width':$(".demo2_div").width()-25+'px'});
	
  				var myLatlng = new qq.maps.LatLng(39.916527,116.397128);
  				var myOptions = {
    				zoom: 4,
    				center: myLatlng,
   				 	mapTypeId: qq.maps.MapTypeId.ROADMAP
 					 }
  				var map = new qq.maps.Map(document.getElementById("demo2_div_project_body"), myOptions);
  
  				$("#demo2_div_project_left_map_select").change(function(){
  					if ($('#demo2_div_project_left_map_select').val() != 'none')
  					geocoder = new qq.maps.Geocoder({
        			complete : function(result){
            		map.setCenter(result.detail.location);
            		map.setZoom(13);
        			}
   					});
 
 						geocoder.getLocation($('#demo2_div_project_left_map_select').val());
  					
  				});
  
 					function maps_event(info,marker,plot_name,plot_address,plot_id,plot_address_map)
  				{
						qq.maps.event.addListener(marker, 'mouseover', function() {
								info.open(); 
								
       				  info.setContent('<div style="text-align:left;white-space:nowrap;'+
        					'margin:10px;"><p>项目：'+plot_name+'</p>\
        					<p>地址：'+plot_address+'</p></div>');
        
        				info.setPosition(new qq.maps.LatLng(plot_address_map.split(',')[0],plot_address_map.split(',')[1])); 
   		 			});
   		 			
   		 			qq.maps.event.addListener(marker, 'mouseout', function() {
								info.close(); 
   		 			});
   		 			
   		 			qq.maps.event.addListener(marker, 'click', function() {
								area(plot_id,plot_name,plot_address_map); 
   		 			});    	
  	
  				}
  
  			new instance.web.Model("pm.project").query(["plot_address","name","plot_address_map"]).all().then(function(result){

					var geocoder = [];	 
					for (i=0;i<result.length;i++)
					{
 						if (result[i].plot_address_map)
						{
 		   				
           			var marker = new qq.maps.Marker({
               		map:map,
               		position: new qq.maps.LatLng(result[i].plot_address_map.split(',')[0],result[i].plot_address_map.split(',')[1])
          			});

                      		
   							var info = new qq.maps.InfoWindow({
        					map: map
    						});     
                       
	          		plot_name=result[i].name;
	          		plot_address = result[i].plot_address;
	          		plot_address_map = result[i].plot_address_map;
	          		plot_id = result[i].id;
	           
	           		$('#demo2_div_project_left_map_select').append("<option val='"+plot_address+"'>"+plot_name+" ("+plot_address+")</option>");
	           
         				maps_event(info,marker,plot_name,plot_address,plot_id,plot_address_map); 
    		
   				
						}
						else
						{
				
						}
					}
		
  	
 		 		});

																					
			}

/*
				function project(){
					
					$("#demo_right_bar_project_title").append("<h2>项目选择:</h2>");  
					$("#demo_right_bar_project_control_hide").html("<img src='pm/static/src/img/close.png' width=15px height=15px></img>");

					
					$("#demo_right_bar_project_control_hide").click(function(){
						$(".demo_right_bar_body_project").hide("drop",{direction:"right"},400);
						$("#demo_right_bar_project").hide("drop",{direction:"right"},500);
						for (i=0;i<5;i++)
						{
							if ($(".demo_right_bar:eq("+i+")").length && $(".demo_right_bar_title:eq("+i+")").html())
							{
								$(".demo_right_bar_control_show:eq("+i+")").show();
								$(".demo_right_bar_control_show:eq("+(i+1)+")").show();	
							}
						}											
					});
					$("#demo_right_bar_project_control_show").click(function(){
						$("#demo_right_bar_project").show("drop",{direction:"right"},500);
						$(".demo_right_bar_body_project").show("drop",{direction:"right"},500);
						$(".demo_right_bar_control_show").hide();
					});
									
  				new instance.web.Model("pm.project").query(["name","code"]).all().then(function(result){
  					for (i=0;i<result.length;i++)
  					{
  						$("#demo_right_bar_project_body").append("<div id='demo_right_bar_project_"+result[i].id+"' \
  									class='demo_right_bar_body_project'>"+result[i].name+"</div>");
  						$("#demo_right_bar_project_"+result[i].id).click(function(){
  							project_id = parseInt($(this).attr('id').split('demo_right_bar_project_')[1]);
  							project_name = $(this).text();
  							area(project_id,project_name); 							  							
  						});
  					}
  					$("#demo_right_bar_start_control_show").show();	  					
  					$("#demo_right_bar_project_control_show").show();					
  
  				});
  				
  				$(".demo2_div_body").hide();
  				$(".demo3_div").hide();
  				$("#demo2_div_project").remove();
  				$(".demo2_div").append("<div id='demo2_div_project' class='demo2_div_body'></div>");
  				$("#demo2_div_project").append("<div id='demo2_div_project_left'>项目列表:</div>");
  				$("#demo2_div_project").append("<div id='demo2_div_project_body'></div>");
  				
  				new instance.web.Model("pm.project").query(["name","code"]).all().then(function(result){
  					for (i=0;i<result.length;i++)
  					{
  						$('#demo2_div_project_body').append("<div id='demo2_div_project_body_project_"+result[i].id+"' class='demo2_div_project_body_child'>"+result[i].name+"</div>");
  						  					
  					}	
  				});					
				}
	*/	
	

			
				function area(project_id,project_name,plot_address_map){
					$("#demo_right_bar_area div").empty();
					$("#demo_right_bar_building div").empty();
									
					$("#demo_right_bar_area_title").append("<h2>分区选择:</h2>"); 
					$("#demo_right_bar_area_control_full").html("<img src='pm/static/src/img/full.png' width=15px height=15px></img>");					  					 
					$("#demo_right_bar_area_control_hide").html("<img src='pm/static/src/img/close.png' width=15px height=15px></img>");


					$("#demo_right_bar_area_control_full").click(function(){
						$(".demo_right_bar_body_area").hide("drop",{direction:"right"},400);
						$("#demo_right_bar_area").hide("drop",{direction:"right"},500);
						for (i=0;i<5;i++)
						{
							if ($(".demo_right_bar:eq("+i+")").length && $(".demo_right_bar_title:eq("+i+")").html())
							{
								$(".demo_right_bar_control_show:eq("+i+")").show();
//								$(".demo_right_bar_control_show:eq("+(i+1)+")").show();	
							}
						}
						
						$(".demo2_div_body").hide();
						$(".demo3_div").hide();
						$("#demo2_div_area").show();						
	 					$("#demo1_div_title").html("项目视图");
  					$("#demo1_div_sub_title").html("("+project_name+")");						
					});
					
					$("#demo_right_bar_area_control_hide").click(function(){
						$(".demo_right_bar_body_area").hide("drop",{direction:"right"},400);
						$("#demo_right_bar_area").hide("drop",{direction:"right"},500);
						for (i=0;i<5;i++)
						{
							if ($(".demo_right_bar:eq("+i+")").length && $(".demo_right_bar_title:eq("+i+")").html())
							{
								$(".demo_right_bar_control_show:eq("+i+")").show();
//								$(".demo_right_bar_control_show:eq("+(i+1)+")").show();	
							}
						}												
					});
					$("#demo_right_bar_area_control_show").click(function(){
						$("#demo_right_bar_area").show("drop",{direction:"right"},500);
						$(".demo_right_bar_body_area").show("drop",{direction:"right"},500);
						$(".demo_right_bar_control_show").hide();
					});					
					
					new instance.web.Model("pm.project.area").query(["name","code","project_id"]).filter([['project_id','=',project_id],]).all().then(function(result){
  					for (i=0;i<result.length;i++)
  					{
  						$("#demo_right_bar_area_body").append("<div id='demo_right_bar_area_"+result[i].id+"' \
  									class='demo_right_bar_body_area'>"+result[i].name+"</div>");
  						$("#demo_right_bar_area_"+result[i].id).click(function(){
  							area_id = parseInt($(this).attr('id').split('demo_right_bar_area_')[1]);
  							area_name = $(this).text();
  							building(area_id,area_name); 							  							
  						});
  					}	  					
 						$(".demo_right_bar_control_show").hide();					
						$(".demo_right_bar").hide();
						$(".demo_right_bar_body div").hide();
//						$("#demo_right_bar_start_control_show").show();	
						$("#demo_right_bar_project_control_show").show();	
						$("#demo_right_bar_area_control_show").show();	  
  				});
  				
  				
  				$("#demo1_div_title").html("项目视图");
  				$("#demo1_div_sub_title").html("("+project_name+")");
  				$(".demo2_div_body").hide();
  				$(".demo3_div").hide();
  				$("#demo2_div_area").remove();
  				$(".demo2_div").append("<div id='demo2_div_area' class='demo2_div_body'></div>");
  				$("#demo2_div_area").append("<div id='demo2_div_area_left'>区域分布:</div>");
  				$("#demo2_div_area").append("<div id='demo2_div_area_body'></div>");
					
											
  				var myLatlng = new qq.maps.LatLng(plot_address_map.split(',')[0],plot_address_map.split(',')[1]);
  				var myOptions = {
    				zoom: 17,
    				center: myLatlng,
   				 	mapTypeId: qq.maps.MapTypeId.ROADMAP
 					 }
  				var map2 = new qq.maps.Map(document.getElementById("demo2_div_area_body"), myOptions);
  
  
 					function maps_event(info,marker,plot_name,plot_id,plot_address_map)
  				{
						qq.maps.event.addListener(marker, 'mouseover', function() {
								info.open(); 
								
       				  info.setContent('<div style="text-align:left;white-space:nowrap;'+
        					'margin:10px;"><p>分区：'+plot_name+'</p></div>');
        
        				info.setPosition(plot_address_map); 
   		 			});
   		 			
   		 			qq.maps.event.addListener(marker, 'mouseout', function() {
								info.close(); 
   		 			});
   		 			
   		 			qq.maps.event.addListener(marker, 'click', function() {
								building(plot_id,plot_name); 
   		 			});    	
  	
  				}
 				
  				new instance.web.Model("pm.project.area").query(["name","plot_address_map"]).all().then(function(result){

					var geocoder = [];	 
					for (i=0;i<result.length;i++)
					{
 						if (result[i].plot_address_map)
						{
 		   				
           			var marker2 = new qq.maps.Marker({
               		map:map2,
               		position: new qq.maps.LatLng(result[i].plot_address_map.split(',')[0],result[i].plot_address_map.split(',')[1])
          			});

								var label2 = new qq.maps.Label({
               		position: new qq.maps.LatLng(result[i].plot_address_map.split(',')[0],result[i].plot_address_map.split(',')[1]),
        					map: map2,
        					content:result[i].name
    						});
                      		
   							var info2 = new qq.maps.InfoWindow({
        					map: map2
    						});     
                       
	          		plot_name=result[i].name;
	          		plot_address_map = new qq.maps.LatLng(result[i].plot_address_map.split(',')[0],result[i].plot_address_map.split(',')[1]);
	          		plot_id = result[i].id;
	           	           
         				maps_event(info2,marker2,plot_name,plot_id,plot_address_map); 
    		
   				
						}
						else
						{
				
						}
					}

  				});

				}
				
				function building(area_id,area_name){
					$("#demo_right_bar_building div").empty();
									
					$("#demo_right_bar_building_title").append("<h2>楼栋选择:</h2>");
					$("#demo_right_bar_building_control_full").html("<img src='pm/static/src/img/full.png' width=15px height=15px></img>");					  										  
					$("#demo_right_bar_building_control_hide").html("<img src='pm/static/src/img/close.png' width=15px height=15px></img>");

					$("#demo_right_bar_building_control_full").click(function(){
						$(".demo_right_bar_body_building").hide("drop",{direction:"right"},400);
						$("#demo_right_bar_building").hide("drop",{direction:"right"},400);
						for (i=0;i<5;i++)
						{
							if ($(".demo_right_bar:eq("+i+")").length && $(".demo_right_bar_title:eq("+i+")").html())
							{
								$(".demo_right_bar_control_show:eq("+i+")").show();
//								$(".demo_right_bar_control_show:eq("+(i+1)+")").show();	
							}
						}
						
						$(".demo2_div_body").hide();
						$(".demo3_div").hide();
						$("#demo2_div_building").show();						
	 					$("#demo1_div_title").html("分区视图");
  					$("#demo1_div_sub_title").html("("+area_name+")");						
					});
					
					$("#demo_right_bar_building_control_hide").click(function(){
						$(".demo_right_bar_body_building").hide("drop",{direction:"right"},400);
						$("#demo_right_bar_building").hide("drop",{direction:"right"},400);
						for (i=0;i<5;i++)
						{
							if ($(".demo_right_bar:eq("+i+")").length && $(".demo_right_bar_title:eq("+i+")").html())
							{
								$(".demo_right_bar_control_show:eq("+i+")").show();
//								$(".demo_right_bar_control_show:eq("+(i+1)+")").show();	
							}
						}												
					});
					$("#demo_right_bar_building_control_show").click(function(){
						$("#demo_right_bar_building").show("drop",{direction:"right"},400);
						$(".demo_right_bar_body_building").show("drop",{direction:"right"},400);
						$(".demo_right_bar_control_show").hide();
					});					
					
					new instance.web.Model("pm.project.building").query(["name","code","project_area_id"]).filter([['project_area_id','=',area_id],]).all().then(function(result){
  					for (i=0;i<result.length;i++)
  					{
  						$("#demo_right_bar_building_body").append("<div id='demo_right_bar_building_"+result[i].id+"' \
  									class='demo_right_bar_body_building'>"+result[i].name+"</div>");
  						$("#demo_right_bar_building_"+result[i].id).click(function(){
  							building_id = parseInt($(this).attr('id').split('demo_right_bar_building_')[1]);
  							building_name = $(this).text();
  							room(building_id,building_name);

  						});
  					}	  					
 						$(".demo_right_bar_control_show").hide();					
						$(".demo_right_bar").hide();
						$(".demo_right_bar_body div").hide();
//						$("#demo_right_bar_start_control_show").show();	
						$("#demo_right_bar_project_control_show").show();	
						$("#demo_right_bar_area_control_show").show();
						$("#demo_right_bar_building_control_show").show();
  				});
				
					$("#demo1_div_title").html("分区视图");
  				$("#demo1_div_sub_title").html("("+area_name+")");					
					$(".demo2_div_body").hide();
					$(".demo3_div").hide();
  				$("#demo2_div_building").remove();
  				$(".demo2_div").append("<div id='demo2_div_building' class='demo2_div_body'></div>");
  				$("#demo2_div_building").css('width','25%');
  				$("#demo2_div_building").append("<div id='demo2_div_building_left'>building列表:</div>");
  				$("#demo2_div_building").append("<div id='demo2_div_building_body'></div>");
  				
  				$('#demo2_div_building_body').append("<a id='demo2_div_cont_back_building' class='demo2_div_cont_back'><div>上一层</div></a>");
  				
  				$("#demo2_div_cont_back_building").click(function(){
  					$(".demo2_div_body").hide();
						$(".demo3_div").hide();
						$("#demo2_div_area").show();
  				});
  				
  				
  				new instance.web.Model("pm.project.building").query(["name","code","project_area_id"]).filter([['project_area_id','=',area_id],]).all().then(function(result){
  					for (i=0;i<result.length;i++)
  					{
  						$('#demo2_div_building_body').append("<div id='demo2_div_building_body_building_"+result[i].id+"' \
  						class='demo2_div_building_body_child'><img height='15px' width='15px' src='/pm/static/src/img/navigation.png'></img><span>"+result[i].name+"</span></div>");
  						
  						$('#demo2_div_building_body_building_'+result[i].id).click(function(){
  							this_id = $(this).attr('id');
  							building_id = parseInt($(this).attr('id').split('demo2_div_building_body_building_')[1]);
  							building_name = $(this).text();
  	//						$(".demo2_div_building_body_child span").css({'text-shadow':'3px 3px 8px white','color':'black'});
  	//						$("#"+this_id+" span").css({'text-shadow':'3px 3px 8px #526DA7','color':'#526DA7'});
  							room(building_id,building_name); 	
  						});
  						  					
  					}	
  				});
					
				}
				
				
				function room(building_id,building_name){
					$("#demo2_div_project").hide();
					$("#demo2_div_area").hide();
					$("#demo2_div_building").show();
					$(".demo3_div").hide();
					$(".demo2_div_building_body_child span").css({'text-shadow':'3px 3px 8px white','color':'#5d616b'});
					$("#demo2_div_building_body_building_"+building_id+" span").css({'text-shadow':'3px 3px 8px #526DA7','color':'#526DA7'});
					
					$("#demo2_div_room").remove();
					$('#demo2_div_room_func').remove();
  				$(".demo2_div").append("<div id='demo2_div_room' class='demo2_div_body'></div>");
  				$("#demo2_div_room").css('width','25%');
  				$("#demo2_div_room").hide();
  				$("#demo2_div_room").append("<div id='demo2_div_room_left'>room列表:</div>");
  				$("#demo2_div_room").append("<div id='demo2_div_room_body'></div>");
  				$("#demo2_div_room").show("drop",{direction:"left"},400);
  				
  				$('#demo2_div_room_body').append("<a id='demo2_div_cont_back_room' class='demo2_div_cont_back'><div>上一层</div></a>");
  				
  				$("#demo2_div_cont_back_room").click(function(){
  					$(".demo2_div_body").hide();
  					$(".demo3_div").hide();	
  					$("#demo2_div_building").show("slide",{direction:"left"},400,callback);
  					function callback()
  					{
  						$("#demo2_div_room").show("drop",{direction:"left"},400);	
  					}  					
  				});
  				
  				new instance.web.Model("pm.project.building.room").query(["name","code","building_id"]).filter([['building_id','=',building_id],]).all().then(function(result){
  					for (i=0;i<result.length;i++)
  					{
  						$('#demo2_div_room_body').append("<div id='demo2_div_room_body_room_"+result[i].id+"' \
  						class='demo2_div_room_body_child'><img height='15px' width='15px' src='/pm/static/src/img/navigation.png'></img><span>"+result[i].name+"</span></div>");
  						
  						$('#demo2_div_room_body_room_'+result[i].id).click(function(){
  							this_id = $(this).attr('id');
  							room_id = parseInt($(this).attr('id').split('demo2_div_room_body_room_')[1]);
  							room_name = $(this).text();
  							$(".demo2_div_room_body_child span").css({'text-shadow':'3px 3px 8px white','color':'#5d616b'});
  							$("#"+this_id+" span").css({'text-shadow':'3px 3px 8px #526DA7','color':'#526DA7'});
  							room_func(room_id,room_name);	
  							
  						});  			  					
  					}
  					$(".demo_right_bar_control_show").hide();					
						$(".demo_right_bar").hide();
						$(".demo_right_bar_body div").hide();
//					$("#demo_right_bar_start_control_show").show();	
						$("#demo_right_bar_project_control_show").show();	
						$("#demo_right_bar_area_control_show").show();
						$("#demo_right_bar_building_control_show").show();
  						
  				}); 					
				}
				
				
				function room_func(room_id,room_name)
				{
					$("#demo2_div_project").hide();
					$("#demo2_div_area").hide();
//					$("#demo2_div_building").show();
					$("#demo2_div_room").show();
					
					$("#demo2_div_room_func").remove();
  				$(".demo2_div").append("<div id='demo2_div_room_func' class='demo2_div_body'></div>");
  				$("#demo2_div_room_func").css('width','25%');
  				$("#demo2_div_room_func").hide();
  				$("#demo2_div_room_func").append("<div id='demo2_div_room_func_left'>功能选择:</div>");
  				$("#demo2_div_room_func").append("<div id='demo2_div_room_func_body'></div>");
  				

					if ($('#demo2_div_building').css('display') === 'none')
					{
  					$("#demo2_div_room_func").show("drop",{direction:"left"},400);
  				}
					else					
					{  				
  					$('#demo2_div_building').hide('slide',{direction:"right"},400,callback1);
  				}
  				  				
  				function callback1(){
  					$("#demo2_div_room").hide();
 // 					$("#demo2_div_cont_back_room").show();
  					$("#demo2_div_room").show("drop",{direction:"right"},400,callback2);  					
  				}
  				
  				function callback2(){
  					$("#demo2_div_room_func").show("drop",{direction:"left"},400);
  				}
  		
  				function callback3(this_id){
  					if ($('#demo2_div_room').css('display') === 'none')
  					{
  							room_detail(room_id,this_id);  						
  					}
  					else
  					{
  						$('#demo2_div_room').hide('slide',{direction:"right"},400,callback4);
  					}
  					
  					function callback4(){
							$("#demo2_div_room_func").hide();
//						$("#demo2_div_cont_back_room_func").show();
							$("#demo2_div_room_func").css({'width':'150px','height':'300px'});
							$("#demo2_div_room_func").show("drop",{direction:"right"},400);
							room_detail(room_id,this_id); 
						}  					
  				}
  		
					
					$('#demo2_div_room_func_body').append("<a id='demo2_div_cont_back_room_func' class='demo2_div_cont_back'><div>上一层</div></a>");
  				
  				$("#demo2_div_cont_back_room_func").click(function(){
  					$(".demo2_div_body").hide();
  					$(".demo3_div").hide();
  					$("#demo2_div_room_func").css({'width':'25%','height':'90%'});	
  					$("#demo2_div_room").show("slide",{direction:"left"},400,callback);
  					function callback()
  					{
  						$("#demo2_div_room_func").show("drop",{direction:"left"},400);	
  					}  					
  				});
  				
  				$('#demo2_div_room_func_body').append("<div id='room_func_select_meter_record' class='demo2_div_room_func_body_child'>\
  						<img height='15px' width='15px' src='/pm/static/src/img/navigation.png'></img>\
  						<span>抄表录入</span></div>");

  				$('#demo2_div_room_func_body').append("<div id='room_func_select_customer_contract' class='demo2_div_room_func_body_child'>\
  						<img height='15px' width='15px' src='/pm/static/src/img/navigation.png'></img>\
  						<span>租赁合同</span></div>");
  						
  				$('#demo2_div_room_func_body').append("<div id='room_func_select_pm_charge' class='demo2_div_room_func_body_child'>\
  						<img height='15px' width='15px' src='/pm/static/src/img/navigation.png'></img>\
  						<span>租赁合同</span></div>");
  						
  				$('.demo2_div_room_func_body_child').click(function(){
  					this_id = $(this).attr('id').split('room_func_select_')[1];
  					$(".demo2_div_room_func_body_child span").css({'text-shadow':'3px 3px 8px white','color':'#5d616b'});
  					$("#room_func_select_"+this_id+" span").css({'text-shadow':'3px 3px 8px #526DA7','color':'#526DA7'});
						callback3(this_id);
  				});		
  					 						
				}
				
				function room_detail(room_id,room_func)
				{				
					$("#demo3_div").empty();
  				demo2_div_room_func_body_top = $('#demo2_div_room_func_body').offset().top-$('body').scrollTop();
  				demo2_div_room_func_body_right = 425;
  				$("#demo3_div").css({'top':demo2_div_room_func_body_top,'bottom':'30px','right':'120px','left':demo2_div_room_func_body_right});  				
//  				$("#demo3_div").append(room_func);
  				
  				$("#demo3_div").show();
  				
  				if (room_func === "meter_record")
  				{
  					$("#demo3_div").append("<table id='demo3_div_table' border='1'></table>");
  					$("#demo3_div_table").append("<tr><th>房间</th><th>表计类别</th><th>收费项目</th><th>表号</th><th>倍率</th>\
  								<th>起数</th><th>止数</th><th>用量</th><th>上次抄表</th><th>本次抄表</th><th>状态</th></tr>");
 
 						new instance.web.Model("pm.meter.record").query(["room_id","meter_category_id","cost_item_id",
 									"meter_id","meter_rate","start_value","end_value","value","last_date","current_date",
 									"state"]).filter([['room_id','=',room_id],]).all().then(function(result){
								
							for (i=0;i<result.length;i++)
							{
								$("#demo3_div_table").append("<tr><td>"+result[i].room_id[1]+"</td><td>"+result[i].meter_category_id[1]+"</td>\
									<td>"+result[i].cost_item_id[1]+"</td><td>"+result[i].meter_id[1]+"</td><td>"+result[i].meter_rate+"</td>\
									<td>"+result[i].start_value+"</td><td>"+result[i].end_value+"</td><td>"+result[i].value+"</td>\
									<td>"+result[i].last_date+"</td><td>"+result[i].current_date+"</td><td>"+result[i].state+"</td></tr>");
							}
  					});			
  				}
  				
  				if (room_func === "customer_contract")
  				{
  					$("#demo3_div").append("<table id='demo3_div_table' border='1'></table>");
  					$("#demo3_div_table").append("<tr><th>房间</th><th>合同编号</th><th>选择租户</th><th>签约日期</th>\
  								<th>法定代表</th><th>联系人</th><th>起租日期</th><th>停租日期</th><th>总天数</th><th>合同状态</th></tr>");
 
 						new instance.web.Model("pm.customer.contract").query(["room_id","name","partner_id",
 									"sign_date","legal_person","contact_person","start_date","end_date","total_days",
 									"state"]).filter([['room_id','=',room_id],]).all().then(function(result){
								
							for (i=0;i<result.length;i++)
							{
								$("#demo3_div_table").append("<tr><td>"+result[i].room_id[1]+"</td><td>"+result[i].name+"</td>\
									<td>"+result[i].partner_id[1]+"</td><td>"+result[i].sign_date+"</td><td>"+result[i].legal_person+"</td>\
									<td>"+result[i].contact_person+"</td><td>"+result[i].start_date+"</td><td>"+result[i].end_date+"</td>\
									<td>"+result[i].total_days+"</td><td>"+result[i].state+"</td></tr>");
							}
  					});
  				}
  				
  				if (room_func === "pm_charge")
  				{
  					$("#demo3_div").append("<table id='demo3_div_table' border='1'></table>");
  					$("#demo3_div_table").append("<tr><th>流水号</th><th>所属房间</th><th>客户名称</th><th>应收金额</th>\
  								<th>滞纳金</th><th>优惠金额</th><th>实收金额</th><th>上次余额</th><th>本次余额</th><th>审核状态</th>\
  								<th>录入人</th><th>录入日期</th></tr>");
 
 						new instance.web.Model("pm.charge").query(["name","room_id","partner_id","receivable_amount",
 									"late_payment_amount","discount_amount","actual_receive_amount",
 									"last_left_amount","current_left_amount","state","input_man",
 									"input_time"]).filter([['room_id','=',room_id],]).all().then(function(result){
								
							for (i=0;i<result.length;i++)
							{
								$("#demo3_div_table").append("<tr><td>"+result[i].name+"</td><td>"+result[i].room_id[1]+"</td>\
									<td>"+result[i].partner_id[1]+"</td><td>"+result[i].receivable_amount+"</td><td>"+result[i].late_payment_amount+"</td>\
									<td>"+result[i].discount_amount+"</td><td>"+result[i].actual_receive_amount+"</td><td>"+result[i].last_left_amount+"</td>\
									<td>"+result[i].current_left_amount+"</td><td>"+result[i].state+"</td><td>"+result[i].input_man[1]+"</td>\
									<td>"+result[i].input_time+"</td></tr>");
							}
  					});
  				}
					
					
				}
				
				
								
 			}
 		});
    	
   	instance.web.client_actions.add('pm.view', 'instance.pm.view');  	
	 	 
 }
    
